//
//  ScucureViewController.m
//  shopping
//
//  Created by 徐双 on 2017/8/31.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "ScucureViewController.h"
#import "ScucureViewCell.h"
#import "ModifierPasswordController.h"
#import "ModifyLoginViewController.h"
#import "personChangePhoneViewController.h"
#import "MineChangeZhiFuMiMaVC.h"
#import "XiuGaiShouJiHaoNewViewController.h"

@interface ScucureViewController ()<UITableViewDataSource,UITableViewDelegate>
{

    NSString *type;
    

}
@property(nonatomic,strong)UITableView * tableView;

@end

@implementation ScucureViewController

- (void)viewWillAppear:(BOOL)animated{
    
    
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:NO];
    
    [self creationData];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"安全中心"];
    
    self.tableView = [[UITableView alloc] init];

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];    
    [self.view addSubview:self.tableView];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"ScucureViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    UIView *viewOf = [[UIView alloc] init];
    viewOf.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, 1);
    [self.view addSubview:viewOf];
    viewOf.backgroundColor = [UIColor colorWithRed:204 / 255.0f green:204 / 255.0f  blue:204 / 255.0f  alpha:1];
    self.tableView.frame = CGRectMake(0, 1, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64);
    
}
- (void)creationData{
    
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
    
    [productParams setValue:token forKey:@"token"];
    [[MNetworkHandler sharedInstance]conURL:adminLxlpersonJudgephone networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            

            type = @"2";
            
            
        }
        
        else if ([[returnData objectForKey:@"code"]intValue]==-1)  {
            
            type = @"1";
            
            
        }else {
//            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
        
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    
    ScucureViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.textLabel.textColor = getColor(@"333333");
    cell.textLabel.font = [UIFont systemFontOfSize:14];
        if (indexPath.row == 0) {
            
            cell.modifyLabel.text = @"修改登录密码";
            
        }else if (indexPath.row ==1){
        
            cell.modifyLabel.text = @"修改支付密码";
            
            
        }else {
        
             cell.modifyLabel.text = @"设置手机号";
            
        }


    return cell;
}
#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        
        ModifyLoginViewController *vc1 = [[ModifyLoginViewController alloc] init];
        
        vc1.hidesBottomBarWhenPushed = YES;
        
        [self.navigationController pushViewController:vc1 animated:YES];
    }else if (indexPath.row == 1){
    
        NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
        NSString *token = [PublicFunction getConfigWithKey:@"token"];
        // NSString *token = @"32728a411b83e29b9836262a72477e3e0dac";
        
        [productParams setValue:token forKey:@"token"];
        [[MNetworkHandler sharedInstance]conURL:adminLxlpersonJudgePaypwd networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
            
            
            if ([[returnData objectForKey:@"code"]intValue]==-1) {

                MineChangeZhiFuMiMaVC *vc = [[MineChangeZhiFuMiMaVC alloc] init];
                
                [self.navigationController pushViewController:vc animated:YES];
                
                
                
            }
            
            else {
                
                ModifierPasswordController *vc2 = [[ModifierPasswordController alloc] init];
                vc2.hidesBottomBarWhenPushed = YES;
                
                [self.navigationController pushViewController:vc2 animated:YES];
                
                
            }
            
        } failureBlock:^(NSError *error) {
            
            NSLog(@"%@",error);
            
//            [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
            
        }];
        

        
        
        
        
        
    
    }else {
        
        if ([type isEqualToString:@"2"]) {
            
            personChangePhoneViewController *vc = [[personChangePhoneViewController alloc] init];
            
            
            [self.navigationController pushViewController:vc animated:YES];
        }else {
        
            
            XiuGaiShouJiHaoNewViewController *vc = [[XiuGaiShouJiHaoNewViewController alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
            
        
        }
        
        
        
        
        
    }

}

@end
